/**
 *  我是卖家-销售订单管理
 */

var setYear = function() {
	var currDate = new Date();
	var year     = currDate.getFullYear();
	$("#data_order_list").children("option[value=3]").html((year-1) + '年');
	$("#data_order_list").children("option[value=4]").html((year-2) + '年');
	$("#data_order_list").children("option[value=5]").html((year-3) + '年');
	$("#data_order_list").children("option[value=6]").html((year-3) + '年以前');
}

$(function(){
	$("#adv_srhBar").inputTips();
	$("#keyword_search_bar").inputTips();
	
	$("#order_keyword").keydown(function(event){
		if(event.keyCode == 13){
			$("#search_order").trigger('click');
		}
	});
	
	//切换高级、基础搜索
	$("#adv_sBr").click(function(){
		var cobj = $(this);
		var display = $("#adv_srhBar").css('display');
		if (display == 'none') {
			$("#adv_srhBar").slideDown('fast');
			cobj.removeClass("adv_sBr_down").addClass("adv_sBr_up").text('返回基础搜索');
		} else {
			$("#adv_srhBar").slideUp('fast');
			cobj.removeClass("adv_sBr_up").addClass("adv_sBr_down").text('使用高级筛选');
		}		
	});	
	
	$("#search_order").click(function(){
		var orderid = $("#orderid").val();
		var uid = $("#uid").val();
		var start_time = $("#start_time").val();
		var end_time = $("#end_time").val();
		var nickname = $("#nickname").val();
		var keyword = $("#order_keyword").val();
		
		location.href = '/?mod=seller&act=order&keyword='+encodeURIComponent(keyword)+'&orderid='+orderid+'&uid='+uid+'&start_time='+start_time+'&end_time='+end_time+'&nickname='+encodeURIComponent(nickname);
		return false;
	});
	
	$(".voteStudent").click(function(){
		var oid = $(this).attr('oid');
		var Box = $.ckAjaxBoxy({
			url : '/?mod=seller&act=credit&do=voteStudent&oid='+oid,
			title : "评价学生",
			width : 540,
			height : 420,
			callback:function(){
				$("#fe_dialogBox").find("a.cancel").unbind().bind('click', function(){
					Box.cancel();
				});
			}
		});
	});
	
	//拒绝听课
	$(".refuseOrder").click(function(){
		var oid = $(this).attr('oid');
		var cost = $(this).attr('cost');
		
		if (cost == 0) {
			//免费课程
			$.ckConfirm({
				message:"你确定要拒绝该学生继续听课吗？",
				ok:function() {
					$.getJSON("/?mod=seller&act=order&do=refuseOrder&oid="+oid+"&rand="+Math.random(), function(ret){
						if (ret.code == 0) {
							window.location.reload();
						} else {
							$.ckAlert({message:ret.data});
						}
					});
				}
			});
		} else {
			var Box = $.ckAjaxBoxy({
				url : '/?mod=seller&act=order&do=refuse&oid='+oid,
				title : "拒绝听课",
				width : 381,
				height : 283,
				callback:function(){
					$("#fe_dialogBox").find("a.cancel").unbind().bind('click', function(){
						Box.cancel();
					});
				}
			});
		}
		
		return false;
	});
	
	$(".editCost").click(function(){
		var oid = $(this).attr('oid');
		var Box = $.ckAjaxBoxy({
			url : '/?mod=seller&act=order&do=editCost&oid='+oid+'&rand='+Math.random(),
			title : "修改订单价格",
			width : 470,
			height : 340,
			callback:function(){
				$("#fe_dialogBox").find("a.cancel").unbind().bind('click', function(){
					Box.cancel();
				});
			}
		});
	});
	
	$('td i.tc-other').click(function() {
		$(this).parent().parent().prevAll().show()
		$(this).parent().hide();
	});
	
	setYear();
	
	$('#data_order_list').change(function() {
		var select = $(this).val();
		if (select != 0) {
			var strat_time = end_time = '';
			var currDate   = new Date();
			var year       = currDate.getFullYear();
			var month      = currDate.getMonth() + 1;
			var day        = currDate.getDate();
			switch (select) {
				case '1':
					strat_time = year + '-' + (currDate.getMonth() - 2) + '-' + day;
					end_time   = year + '-' + month + '-' + day;
					break;
				case '2':
					strat_time = year + '-1-1';
					end_time   = year + '-' + month + '-' + day;
					break;
				case '3':
					strat_time = (year - 1) + '-1-1';
					end_time   = (year - 1) + '-12-31';
					break;
				case '4':
					strat_time = (year - 2) + '-1-1';
					end_time   = (year - 2) + '-12-31';
					break;
				case '5':
					strat_time = (year - 3) + '-1-1';
					end_time   = (year - 3) + '-12-31';
					break;
				case '6':
					strat_time = '1990-1-1';
					end_time   = (year - 3) + '-1-1';
					break;
			}
			var url = 'http://www.chuanke.com/?mod=seller&act=order&start_time=' + strat_time + '&end_time=' + end_time;
			location.href = url;
		}
	});
});